package com.yunshipei.core.model;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.ArrayList;
import java.util.List;

public class WaterMarkConfig implements Parcelable {

    private boolean showDateTime = false;
    private boolean showDeviceID = false;
    private String wtmColor = "#CDCDCD";
    private int wtmTextSize = 50;
    private float wtmTransparency = 0.25f;
    private List<String> wtmTexts = new ArrayList<>();

    private WaterMarkConfig() {
    }

    protected WaterMarkConfig(Parcel in) {
        showDateTime = in.readByte() != 0;
        showDeviceID = in.readByte() != 0;
        wtmColor = in.readString();
        wtmTextSize = in.readInt();
        wtmTransparency = in.readFloat();
        wtmTexts = in.createStringArrayList();
    }

    public static final Creator<WaterMarkConfig> CREATOR = new Creator<WaterMarkConfig>() {
        @Override
        public WaterMarkConfig createFromParcel(Parcel in) {
            return new WaterMarkConfig(in);
        }

        @Override
        public WaterMarkConfig[] newArray(int size) {
            return new WaterMarkConfig[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte((byte) (showDateTime ? 1 : 0));
        dest.writeByte((byte) (showDeviceID ? 1 : 0));
        dest.writeString(wtmColor);
        dest.writeInt(wtmTextSize);
        dest.writeFloat(wtmTransparency);
        dest.writeList(wtmTexts);
    }

    private void setShowDateTime(boolean showDateTime) {
        this.showDateTime = showDateTime;
    }

    private void setShowDeviceID(boolean showDeviceID) {
        this.showDeviceID = showDeviceID;
    }

    private void setWtmColor(String wtmColor) {
        this.wtmColor = wtmColor;
    }

    private void setWtmTextSize(int wtmTextSize) {
        this.wtmTextSize = wtmTextSize;
    }

    private void setWtmTransparency(float wtmTransparency) {
        this.wtmTransparency = wtmTransparency;
    }

    private void setWtmTexts(List<String> wtmTexts) {
        this.wtmTexts = wtmTexts;
    }

    public boolean isShowDateTime() {
        return showDateTime;
    }

    public boolean isShowDeviceID() {
        return showDeviceID;
    }

    public String getWtmColor() {
        return wtmColor;
    }

    public int getWtmTextSize() {
        return wtmTextSize;
    }

    public float getWtmTransparency() {
        return wtmTransparency;
    }

    public List<String> getWtmTexts() {
        return wtmTexts;
    }

    public static final class Builder {

        private WaterMarkConfig waterMarkConfig;

        public Builder() {
            waterMarkConfig = new WaterMarkConfig();
        }

        public Builder setShowDateTime(boolean showDateTime) {
            waterMarkConfig.setShowDateTime(showDateTime);
            return this;
        }

        public Builder setShowDeviceID(boolean showDeviceID) {
            waterMarkConfig.setShowDeviceID(showDeviceID);
            return this;
        }

        public Builder setWtmColor(String wtmColor) {
            waterMarkConfig.setWtmColor(wtmColor);
            return this;
        }

        public Builder setWtmTextSize(int wtmTextSize) {
            waterMarkConfig.setWtmTextSize(wtmTextSize);
            return this;
        }

        public Builder setWtmTransparency(float wtmTransparency) {
            waterMarkConfig.setWtmTransparency(wtmTransparency);
            return this;
        }

        public Builder setWtmTexts(List<String> wtmTexts) {
            if (wtmTexts != null && wtmTexts.size() > 0) {
                List<String> wtms = waterMarkConfig.getWtmTexts();
                wtms.addAll(wtmTexts);
            }
            return this;
        }

        public WaterMarkConfig build() {
            return waterMarkConfig;
        }
    }
}
